home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / trans / deallocTransPages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  5.9 KB  |  205 lines

  1. /*
  2.  *   $RCSfile: deallocTransPages.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:02 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "bf_macro.h"
  57. #include "volume.h"
  58. #include "openlog.h"
  59. #include "trans.h"
  60. #include "page.h"
  61. #include "bitmap.h"
  62. #include "deallocinfo.h"
  63. #include "io_extfuncs.h"
  64. #include "trans_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "bm_extfuncs.h"
  67. #include "bm_globals.h"
  68. #include "io_globals.h"
  69.  
  70.  
  71. /*
  72.  *    This function traverses the list of pages to deallocate and
  73.  *    sets the bitmap bit to free the page.  For each bitmap
  74.  *    page the number of bits changed is remembered.
  75.  *
  76.  *    NOTE: This code does not obtain any semaphores on the bitmap
  77.  *        pages since they are fixed in the buffer pool and this
  78.  *        function makes no call which would cause it to block.
  79.  */
  80.  
  81.  int
  82. deallocTransPages (
  83.  
  84.     TRANSREC        *transRec,
  85.     LIST            *pendingBitmapList   
  86. )
  87. {
  88.  
  89.     PAGEDEALLOCINFO *currPage;
  90.     PAGE2SIZE        page2size;
  91.     PAGECONTEXT        *currBitmapPage;
  92.     PID                bitmapPid;
  93.     VOLREC            *volRec;
  94.     int                index;
  95.  
  96.  
  97.     TRACE(TR_TRANS, TR_LEVEL_1);
  98.  
  99.  
  100.     /*
  101.      *    See if there is any work to be done;
  102.      */
  103.     currPage = (PAGEDEALLOCINFO*) FIRST_LIST_ELEMENT(&(transRec->pageDeallocList));
  104.     if (currPage == NULL) {
  105.         SM_ASSERT(LEVEL_3, LIST_EMPTY(pendingBitmapList));
  106.         return(esmNOERROR);
  107.     }
  108.  
  109.     SM_ASSERT(LEVEL_3, !LIST_EMPTY(pendingBitmapList));
  110.  
  111.     /*
  112.      *    Initialize locals
  113.      */
  114.     currBitmapPage = (PAGECONTEXT*) FIRST_LIST_ELEMENT(pendingBitmapList);
  115.     SM_ASSERT(LEVEL_1, currBitmapPage != NULL);
  116.  
  117.     /*
  118.      *    Process each chunk of pages
  119.      */
  120.     while ((currPage = (PAGEDEALLOCINFO*) listDeq(&(transRec->pageDeallocList))) != NULL) {
  121.         
  122.         CHECK_PAGEDEALLOCINFO_MAGIC(currPage);
  123.         page2size = currPage->page2size;
  124.  
  125.         /*
  126.          *    Deallocate each physical page
  127.          */
  128.         for (index = 0; index < BLOCKCOUNT(page2size); index++) {
  129.  
  130.             /*
  131.              *    calculate the page that the bit to set lies on
  132.              */
  133.             bitmapPid.page = BIT_TO_PAGE(currPage->pid.page + index);
  134.             bitmapPid.volid = currPage->pid.volid;
  135.  
  136.             /*
  137.              *    If we're not currently looking at the correct
  138.              *    bitmap page info, find it.
  139.              */
  140.             if (!PIDEQ(bitmapPid, currBitmapPage->pid)) {
  141.                 currBitmapPage = (PAGECONTEXT*) FIRST_LIST_ELEMENT(pendingBitmapList);
  142.                 while (currBitmapPage != NULL) {
  143.                     if (PIDEQ(bitmapPid, currBitmapPage->pid)) {
  144.                         /* the page is the one we want */
  145.                         break;
  146.                     }
  147.                     currBitmapPage = (PAGECONTEXT*) NEXT_LIST_ELEMENT(&(currBitmapPage->list));
  148.                 }
  149.                 SM_ASSERT(LEVEL_3, currBitmapPage!=NULL);
  150.             }
  151.  
  152.             /*
  153.              *    Make sure the page isn't already marked free,
  154.              *    then mark it free and update the count of bits set
  155.              */
  156.             SM_ASSERT(LEVEL_3, !bm_CheckSet((UFOUR *) currBitmapPage->groupLink->bufFrame, (FOUR) BIT_IN_PAGE(currPage->pid.page + index)));
  157.             bm_SetBit((UFOUR *) currBitmapPage->groupLink->bufFrame, (FOUR) BIT_IN_PAGE(currPage->pid.page + index));
  158.             currBitmapPage->bitsChanged++;
  159.             
  160.         }    
  161.  
  162.         /*
  163.          *    Remove the page from the buffer and
  164.          *    Return the page info to the Pool
  165.          */
  166.         bf_InvalidatePage(&(currPage->pid));
  167.         poolEnq(&PageDeallocInfoPool, &(currPage->list));
  168.     }
  169.  
  170.     /*
  171.      *    traverse the pendingBitmaplist and decrement the volhdr free 
  172.      *    count by the number of pages deallocated.  also decrement the 
  173.      *    pendingOpCount for the volhdr and the bitmap page and unfix the 
  174.      *    bitmap page .  Then return the bitmap page context to the pool
  175.      */
  176.     while ((currBitmapPage = (PAGECONTEXT*) listDeq(pendingBitmapList)) != NULL) {
  177.         /*
  178.          *    find the volume header, 
  179.          *    increment the number of free pages
  180.          *    decrement the number of pending operations for it
  181.          */
  182.         volRec = io_FindVolRec(currBitmapPage->pid.volid);
  183.         if (volRec == NULL) {
  184.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  185.         }
  186.         if (waitSemaphore(&(volRec->headerLink->pageHash->semaphore)) != esmNOERROR) {
  187.             SM_ERROR(TYPE_FATAL, esmINTERNAL);
  188.         }
  189.         io_ChangeVolFreePages(volRec, currBitmapPage->bitsChanged);
  190.         volRec->headerLink->pageHash->pendingOpCount--;
  191.         signalSemaphore(&(volRec->headerLink->pageHash->semaphore));
  192.  
  193.         /*
  194.          *    Remove the pending operation on the bitmap page,
  195.          *    unfix it, and return it to the pool
  196.          */
  197.         currBitmapPage->groupLink->pageHash->pendingOpCount--;
  198.         bf_UnfixPage(currBitmapPage->groupLink, BF_DEFAULT, TRUE);
  199.         poolEnq(&PageContextPool, &(currBitmapPage->list));
  200.     }
  201.  
  202.     SM_ASSERT(LEVEL_3, io_CheckAllVolumes() == esmNOERROR);
  203.     return(esmNOERROR);
  204. }
  205.